package com.gcq.javawork.controller;


import com.gcq.javawork.common.Result;
import com.gcq.javawork.model.domain.Goods;
import com.gcq.javawork.model.domain.User;
import com.gcq.javawork.service.impl.GoodsServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.gcq.javawork.constatnts.BaseMessage.USER_PERMISSION_ERROR;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsServiceImpl goodsService;

    /**
     * 商品查询
     * @param goodName
     * @return
     */
    @GetMapping("/search")
    public Result<List<Goods>> searchUserByName(String goodName, HttpServletRequest httpServletRequest){

        if (goodName == null){
            List<Goods> list = goodsService.list();
            if (list == null || list.size() == 0){
                return null;
            }
            return Result.success(list);
        }

        List<Goods> searchGoods = goodsService.searchGoods(goodName);

        return Result.success(searchGoods);
    }

}
